﻿using OpenQA.Selenium;
using OpenQA.Selenium.Support.PageObjects;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WebUITestDemo
{
    public class LoginPage
    {
        public IWebDriver Driver { get; set; }

        public LoginPage(IWebDriver driver)
        {
            Driver = driver;
            PageFactory.InitElements(driver, this);
        }

        [FindsBy(How = How.Id, Using = "input1")]
        protected IWebElement txtUserName;

        [FindsBy(How = How.Id, Using = "input2")]
        protected IWebElement txtPassword;

        [FindsBy(How = How.Id, Using = "signin")]
        protected IWebElement btnLogin;

        [FindsBy(How = How.Id, Using = "tip_btn")]
        protected IWebElement lblTip;

        public string Tip { get; set; }

        public void Login(string userName,string password)
        {
            txtPassword.Clear();
            txtUserName.Clear();

            txtUserName.SendKeys("cnblogs");
            txtPassword.SendKeys("sino5802486");

            btnLogin.Click();

            WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
            wait.Until(ExpectedConditions.TextToBePresentInElementLocated(By.Id("tip_btn"), "用户名或密码错误\r\n\r\n联系 contact@cnblogs.com"));

            Tip= lblTip.Text;
        }
    }
}
